import React from "react";
import { DownOutlined } from "@ant-design/icons";
import { Tree } from "antd";
import { treeData } from "../config/treeData";

const App = () => {
//   const navigate = useNavigate();
  const onSelect = (selectedKeys, info) => {
    console.log("selected", selectedKeys, info);
    const { key } = info.node;
    const level = key.split("-").length;
    // 如果选中&&是最后一层就进行跳转
    if (info.selected && level === 3) {
      console.log(key);
        window.history.pushState({},null,"/"+key)
    }
  };
  const TreeStyle = {
    minWidth: 300,
    backgroundColor: "#FAFFD1",
    padding: 20,
    minHeight: "100vh",
    height: "100vh",
    overflowY: "scroll",
  };

  return (
    <Tree
      style={TreeStyle}
      showLine
      switcherIcon={<DownOutlined />}
      onSelect={onSelect}
      treeData={treeData}
    />
  );
};

export default App;
